/* * * * M A P V I S I O N   L I C E N S E  *****************************************************************
 *
 * This MapVision software is © Filip Zavadil 2013. It is licensed under the LGPL license.
 * This MapVision software dynamically links to unmodified Qt5 Library.
 *
 * The Qt5 Library is © 2013 Qt® and/or its subsidiary(-ies), and is licensed under the
 * GNU Lesser General Public License version 2.1 with Qt® LGPL exception version 1.1.
 * Qt5 library is free software; you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
 * Qt5 library is provided “AS IS”, without WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
 *
 * As an additional permission to the GNU Lesser General Public License version 2.1, the object
 * code form of a “work that uses the Library” may incorporate material from a header file that is
 * part of the Library. You may distribute such object code under terms of your choice,
 * provided that: (i) the header files of the Library have not been modified; and (ii)
 * the incorporated material is limited to numerical parameters, data structure layouts, accessors,
 * macros, inline functions and templates; and (iii) you comply with the terms of Section 6 of the
 * GNU Lesser General Public License version 2.1.
 *
 * Moreover, you may apply this exception to a modified version of the Library, provided that such
 * modification does not involve copying material from the Library into the modified Library’s header
 * files unless such material is limited to (i) numerical parameters; (ii) data structure layouts;
 * (iii) accessors; and (iv) small macros, templates and inline functions of five lines or less in length.
 *
 * Furthermore, you are not required to apply this additional permission to a modified version of the Library.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this package;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

 * The source code for Qt 5.X SDK is available from Qt Project here:
 * http://download.qt-project.org/official_releases/qtcreator/2.7/2.7.0/qt-creator-2.7.0-src.zip.
 *
 * ****************************** M A P V I S I O N    S O F T W A R E  ************************************
 *
 * Author:       Filip Zavadil
 * Description:  Software for displaying and exporting map tiles.
 * The sources and executables of MapVision software are available:
 *    - from project hosting on CodePlex.com :   http://mapvision.codeplex.com
 *    - from GIT repositories on Gitorious.org:  https://gitorious.org/mapvision
 * Visit MapVision fanpage on Facebook.com:      https://www.facebook.com/pages/Mapvision/631827753513935
 *
 * *********************************************************************************************************
*/

#ifndef ZAVAPROJ_H
#define ZAVAPROJ_H


#include <QRect>
#include <QPoint>
#include <cmath>


class ZavaProj {


public:
    enum Yaxis { BOTTOM, TOP };
    /* different origin of Y-axis in TMS and WMTS ...
     * BOTTOM  - it is standard TMS
     * TOP     - it is standart WMTS like (Google/OSM ...)
     */

    enum coorsFormat { DegreeMinuteSecond, DegreeMinute, Degree, DecimalWorldSide, Decimal  };
    /* output of coordinates (WGS84) in human-readable format
     * example of coors of Hierro island; also known as Ferro :) QPoint(27.727906,-18.017578)
     * DegreeMinuteSecond  -  27°43'40.4616"N, 18°1'3.2808"W
     * DegreeMinute        -  27°43.82895'N, 18° 0.26050'W
     * Degree              -  27.7304825°N, 18.0043417°W
     * DecimalWorldSide    -  27.7304825N, 18.0043417W
     * Decimal             -  27.7304825, -18.0043417
     */



    ZavaProj();

    // TILING names (coordinates for TMS) (in Tile Map Service format)
    QPoint lonlat2tileFormat(double lon, double lat, int zoom,Yaxis);
    QPoint lonlat2tileFormat(QPointF lonlat, int zoom,Yaxis);

    QPointF tileFormat2lonlat(int x, int y, int zoom,Yaxis);
    QPointF tileFormat2lonlat(QPoint xy, int zoom,Yaxis);

    // pixels to longtitude and latitude
    QPointF pixels2lonlat(QPoint pixelPos, int zoom);
    QPoint lonlat2pixels(QPointF lonlat, int zoom);

    // pixels to tile coordinate format (coordinates for TMS)
    QPoint pixels2tileFormat(QPoint xy, int zoom, ZavaProj::Yaxis origin);
    QPoint tileFormat2pixels(QPoint xy, int zoom, ZavaProj::Yaxis origin);

    // different origin of Y-axis in TMS x WMTS
    int convertYaxis(int yTile, int zoom);
    QPoint convertYaxis(QPoint tile, int zoom);

    // rect for tile in scene pixels
    QRect rectForTile(QPoint tile);

    // reference Point in scenePixels
    QPoint pointForTile(QPoint tileFormat,int zoom);

    double Clip(double n, double minValue, double maxValue);

    // convert coordinates in Degree-Minute-Second format to decimal
    QPointF dms2lonlat(QString);

    // convert coordinates in decimal format to Degree-Minute-Second format
    QString lonlat2dms(QPointF);
    QString lonlat2dms(QPointF,int prec);

    // distance computation
    double getDistance(QPointF,QPointF);

    QPointF project(QPointF lonlat, QString EPSGcode,bool isDegree);

    QPointF lonlat2UTM(QPointF);
    QPointF UTM2lonlat(QPointF);

private:
   double dms2double(QString);
   QString double2dms(double,int);



};
#endif // ZAVAPROJ_H
